function studentAdd_clicked()
{
	$("#msg_addstudent").html('')
	var mail=$("#studentMail").val();
	var validmail=CheckEmail(mail);
	if(validmail==false)
	{
		$("#msg_addstudent").append('*邮件格式不正确   ')
		}
	var number=$("#studentNumber").val();
	var validnumber=CheckNumber(number);
	if(validnumber==false)
	{
		$("#msg_addstudent").append('*学号格式不正确   ')
		}
	var name=$("#studentName").val();
	if(name=='')
	{
		$("#msg_addstudent").append('*姓名空   ')
		}
	var sex=$("#studentSex").val()
	var pwd=$.trim($("#setPassword").val())
	if(pwd=='')
		pwd=$.trim(number);
	AddAccount_Student($.trim(name),$.trim(number),$.trim(mail),$.trim(sex),pwd);
}
function parentAdd_clicked()
{
	$("#msg_addparent").html('')
	var mail=$("#parentMail").val();
	var validmail=CheckEmail(mail);
	if(validmail==false)
	{
		$("#msg_addparent").append('*邮件格式不正确   ')
		}
	var number=$("#studentNumber2").val();
	var validnumber=CheckNumber(number);
	if(validnumber==false)
	{
		$("#msg_addparent").append('*学号格式不正确   ')
		}
	var nameStu=$("#studentName2").val();
	if(nameStu=='')
	{
		$("#msg_addparent").append('*学生姓名空   ')
		}
	var namePar=$("#parentName").val();
	if(namePar=='')
	{
		$("#msg_addparent").append('*家长姓名空   ')
		}
	AddAccount_Parent($.trim(mail),$.trim(number),$.trim(nameStu),$.trim(namePar));
}

function AddAccount_Student(name,number,mail,sex,pwd)
{
	if($("#msg_addstudent").html()!='')
	{
		alert('发生错误')
		return;
	}
	else
	{
		$.ajax({
            type: 'Post',
            url: '/adduser_action_addstudent',
            data: "studentName="+name+"&studentNumber="+number+"&studentMail="+mail+"&studentSex="+sex+"&pwd="+pwd,
            success: function(response) {
                if(response=='add succeed')
				{alert('添加成功')}
				else if(response=='same student')
				{alert('不能添加已有学生')}
				if(response=='failed')
				{alert('添加失败')}
            	}
        	})
	}
}
function AddAccount_Parent(mail,number,nameStu,namePar)
{
	if($("#msg_addparent").html()!='')
	{
		alert('发生错误')
		return;
	}
	else
	{
		$.ajax({
            type: 'Post',
            url: '/adduser_action_addparent',
            data: "parentMail="+mail+"&studentNumber="+number+"&studentName="+nameStu+"&parentName="+namePar,
            success: function(response) {
                alert(response);
            	}
        	})
	}
}

function checkSetPassword()
{
	var checked=$("#checkPassword").attr("checked")
	if(checked)
	{
		$("#setPassword").removeClass("hide");	
	}
	else
	{
		$("#setPassword").addClass("hide");	
		}
}

function CheckEmail(mail)   
{   
	  var   patrn=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;     
	  if   (!patrn.exec(mail))     
	  { return false; }   
	  else { return true; }   
}
function CheckNumber(num)
{
	var patrn=/^[0-9]*[1-9][0-9]*$/;
	if   (!patrn.exec(num))     
	  return false;  
	else 
	  return true;  
}

